/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cms.util;

import javax.naming.InitialContext;

/**
 *
 * @author Timmy
 */
public class EjbLocator {
    private InitialContext initCtx = null; 
    private static EjbLocator locator = null; 
    
    static 
    {
        locator = new EjbLocator();
    }
    
    private EjbLocator()
    {
        try 
        {
            initCtx = new InitialContext();
        }
        catch(Exception ex)
        {
            initCtx = null; 
        }
    }
    
    public static EjbLocator getInstance() 
    {
        return locator; 
    }
    
    public<T> T LookUpBeanByName(Class<T> t, String beanName)
    {
        try 
        {
            if (initCtx != null) {
                return t.cast(initCtx.lookup(beanName));
            }
            
            return null; 
        }
        catch(Exception n)
        {
            return null; 
        }
    }
}
